package com.wjd.wshow.common.resource.pojo;

import com.wjd.wshow.common.resource.AbstractResource;
import com.wjd.wshow.common.resource.ResourceType;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;

/**
 * 上传资源
 */
public class UploadResource extends AbstractResource {

    /**
     * 上传资源id，和数据库保存的id不一样
     */
    private String resId;

    /**
     * 上传资源大小
     */
    private long size;

    /**
     * 上传资源类型
     */
    private ResourceType type;

    /**
     * 上传文件名
     */
    private String filename;

    /**
     * 资源保存路径
     */
    private Path path;

    /**
     * 上传的文件输入流
     */
    private InputStream inputStream;

    @Override
    public String getResId() {
        return resId;
    }

    @Override
    public ResourceType getType() {
        return type;
    }

    @Override
    public Path getPath() {
        return path;
    }

    @Override
    public long getSize() {
        return size;
    }

    @Override
    public InputStream getInputStream() {
        return inputStream;
    }

    public String getFilename() {
        return filename;
    }

    public void setResId(String resId) {
        this.resId = resId;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public void setPath(Path path) {
        this.path = path;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public void setType(ResourceType type) {
        this.type = type;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public void close() {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
